package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.BaseCategoryViewService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {

	@Autowired
	private BaseCategoryService baseCategoryService;

	@Autowired
	private BaseCategoryViewService baseCategoryViewService;


	/**
	 * 查询所有一级分类
	 * @return
	 */
	@GetMapping("/category/findAllCategory1")
	public Result<List<BaseCategory1>> findAllCategory1() {
		List<BaseCategory1> list = baseCategoryService.list();
		return Result.ok(list);
	}

	/**
	 * 查询所有分类（1、2、3级分类）
	 *
	 * @return
	 */
	@Operation(summary = "查询所有分类（1、2、3级分类）")
	@GetMapping("/category/getBaseCategoryList")
	public Result getBaseCategoryList(){
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}

	@Operation(summary = "根据一级分类Id获取分类属性（标签）列表")
	@GetMapping("/category/findAttribute/{category1Id}")
	public Result findAttribute(@PathVariable Long category1Id){
		List<BaseAttribute> list =  baseCategoryService.selectAttribute(category1Id);
		return Result.ok(list);
	}


	@PostMapping("/albumInfo/saveAlbumInfo")
	@Operation(summary = "新增专辑")
	public Result saveAlbumInfo(@RequestBody AlbumInfoVo albumInfoVo){
		baseCategoryService.saveAlbumInfo(albumInfoVo,1L);
		return Result.ok();
	}

	/**
	 * 根据三级分类ID(视图主键)查询分类视图对象
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类ID查询分类视图对象")
	@GetMapping("/category/getCategoryView/{category3Id}")
	public Result<BaseCategoryView> getCategoryView(@PathVariable Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryViewService.getById(category3Id);
		return Result.ok(baseCategoryView);
	}

	/**
	 *  根据一级分类查找三级分类
	 * @param category1Id
	 * @return
	 */
	@GetMapping("/category/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3> > findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3>  baseCategory3 = baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(baseCategory3);
	}


	/**
	 *  根据一级分类id获取全部分类信息
	 */
	@GetMapping("/category/getBaseCategoryList/{category1Id}")
	public Result<JSONObject> getBaseCategoryList(@PathVariable Long category1Id){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryListByCategory1Id(category1Id);
		return Result.ok(jsonObject);
	}







}

